{extend name="common/application" /}
{block name="title"}<title id="title">店铺</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/store.css"/>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
<style>
    .sp1 {
        width: 34px;
        height: 16px;
        background-color: #17c6ac;
        color: #ffffff;
        font-size: 12px;
        line-height: 16px;
        text-align: center;
        margin-right: 10px;
    }
	.serviceHeader{margin-top:13px;}
	.publist-box{min-height:976px;}
	.nodatas{text-align: center;}
	.nodatas img{display: inline-block;margin-top: 200px;margin-bottom: 20px;}
</style>
{/block}


{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix" style="padding-top: 14px;">
        <!--店铺信息-->
        <div class="storeArea fl">
            <div class="basicInfo">
                <a class="storeLogo userImg" href="javascript:;">
                    <img src="/static/web/images/76.png" class="icon-wapper hide">
                    <img id="images" src="_IMG_/store.jpg" class="icon">
                </a>
                <h4 class="storeName name text_overflow"></h4>
                <input type="hidden" id="id">
                <p>卖家：<span class="sellerman name"></span></p>
                <br/>
                <span class="icons sp1 name"></span>
                <span class="icons icon-ensure"></span>
            </div>
            <p>成交量<span class="name"></span>次</p>
            <p>本店铺一共<span class="name"></span>件商品，其中交易类商品<span class="name"></span>件，服务类商品<span class="name"></span>件。
            </p>
            <p class="name">
            </p>
            <input type="hidden" id="contact">
            <!--<p>主营：专利转让、商标版权与专利转让专利转让、商标版权与专利转让专利转让、商标版权与专利转让专利转让、商标版权与专利转让</p>-->
            <a class="contactStore" href="javascript:;"></a>
            <a class="contactStore" href="javascript:;">联系卖家</a>
        </div>
        <!--店铺商品列表-->
        <div class="productList fr">
            <div class="productsListHeader">
                <a class="productType on" href="javascript:;">交易类商品</a>
                <a class="productType" href="javascript:;">服务类商品</a>
            </div>
            <input type="hidden" id="value">
            <input type="hidden" id="index">
            <input type="hidden" id="center">
			<input type="hidden" id="user_id">
            <div class="serviceHeader">
                <div class="serviceNavi fl">
                    <a class="sortType active" value="0" href="javascript:;">综合排序</a>
                    <a class="sortType" value="1" href="javascript:;">授权量</a>
                    <a class="sortType" value="2" href="javascript:;">评价量</a>
                    <a class="sortType" value="3" href="javascript:;">时间</a>
                </div>
                <div class="priceRange fl">
                    <a class="showDiv fl" href="javascript:;">价格<span class="icons icon-arrowdown"></span></a>
                    <input class="minPrice" type="number" placeholder="￥"/>
                    <span class="fl">-</span>
                    <input class="maxPrice" type="number" placeholder="￥"/>
                    <div class="hideBox sortBox">
                        <a class="asc cur" href="javascript:;">按价格从低到高</a>
                        <a class="desc" href="javascript:;">按价格从高到低</a>
                    </div>
                    <a class="sendButton" href="javascript:;">确定</a>
                </div>
                <div class="total fr">
                    <p class="mr20">共<span class="num" id="count"></span>件商品</p>
                    <a class="prev" href="javascript:;">
                        <span class="icons icon-prev hide"></span>
                        <span class="icons icon-grey-prev"></span>
                    </a>
                    <p><span class="currentPage">1</span>/<span class="allPage"></span></p>
                    <a class="next" href="javascript:;">
                        <span class="icons icon-next"></span>
                        <span class="icons icon-grey-next hide"></span>
                    </a>
                </div>
            </div>
            <div class="publist-box">
                <div class="serviceArea">
                </div>
            </div>

            <div class="publist-box hide">
                <div class="serviceArea">
                </div>
            </div>
            <div class="page"></div>
            <div class="page"></div>
        </div>
        <!--推荐区-->
        <div class="recommendAreas fl">
            <div class="recommendArea services">
                <div class="recommendHeader">
                    <span class="fl">推荐交易</span>
                    <a class="refreshBtn fr" href="javascript:;"><span class="icons icon-refresh"></span></a>
                </div>
                <div class="recommendCon">

                </div>
            </div>
            <div class="recommendArea trades mt20">
                <div class="recommendHeader">
                    <span class="fl">推荐服务</span>
                    <a class="refreshBtn fr" href="javascript:;"><span
                            class="icons icon-refresh"></span></a>
                </div>
                <div class="recommendCon">
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<!-- 脚本引入 -->
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/trading.js"></script>
<script>
    $(function () {
        var id = decodeURI(window.location.href.split("?")[1]);
        $("#contact").val(id);
        hot_view();
        get_view();
        postfile(1, id, '交易类商品');
    });


    /*交易市场与服务市场*/
    $('.productsListHeader a').on('click', function () {
        $('.productsListHeader a').removeClass('on');
        $(this).addClass('on');
        var num = $(".productsListHeader a").index(this);
        $(".publist-box").hide();
        $(".publist-box").eq(num).show();
        var text = $(this).text();
        $("#index").val(text);
        if (text == '服务类商品') {
            $(".page").eq(0).hide();
            $(".page").eq(1).show();
            $("#value").val("");
            $('.maxPrice').val("");
            $('.minPrice').val("");

        } else {
            $(".page").eq(1).hide();
            $(".page").eq(0).show();
            $("#value").val("");
            $('.maxPrice').val("");
            $('.minPrice').val("");
        }
        var id = decodeURI(window.location.href.split("?")[1]);
        postfile(1, id, text);
    });

    $('.prev').on('click', function () {
        var id = decodeURI(window.location.href.split("?")[1]);
        var prev_num = parseInt($('.currentPage').html()) - 1;
        var index = $("#index").val();
        if (prev_num != 0) {
            postfile(prev_num, id, index);
        }
    });
    $('.next').on('click', function () {
        var id = decodeURI(window.location.href.split("?")[1]);
        var next_num = parseInt($('.currentPage').html()) + 1;
        var max_num = parseInt($('.allPage').html());
        var index = $("#index").val();
        var value = $("#value").val();
        if (next_num <= max_num) {
            postfile(next_num, id, index, value);
        }
    });

    $(".sortType").on('click', function () {
        var value = $(this).attr('value');
        var index = $("#index").val();
        $("#value").val(value);
        var id = decodeURI(window.location.href.split("?")[1]);
        postfile(1, id, index, value);
    });
    $(".asc").click(function () {
        var index = $("#index").val();
        $("#value").val(4);
        var id = decodeURI(window.location.href.split("?")[1]);
        postfile(1, id, index, 4);
    });
    $(".desc").click(function () {
        var index = $("#index").val();
        $("#value").val(5);
        var id = decodeURI(window.location.href.split("?")[1]);

        postfile(1, id, index, 5);
    });

    $(".sendButton").on('click', function () {
        var index = $("#index").val();
        var value = $("#value").val();
        var id = decodeURI(window.location.href.split("?")[1]);

        postfile(1, id, index, value);
    });

    function postfile(page, id, text, value) {
        var userinfo = $.cookie('userinfo');
		if (text == '服务类商品') {
			var index = 2;
		} else {
			var index = 1;
		}
		if(userinfo){
			var user_login = $.base64.decode(userinfo).split(",");
			var user = user_login[0];
		}else{
			var user = 0;
		}
		
		var minmoney = $('.minPrice').val();
		var maxmoney = $('.maxPrice').val();
		$.ajax({
			type: "get",
			url: "{:url('api/trading/center')}",
			data: {
				'page': page,
				'uid': id,
				'index': index,
				'value': value,
				'minmoney': minmoney,
				'maxmoney': maxmoney,
				'user': user
			},
			dataType: 'jsonp',
			success: function (msg) {
				if (msg.code == 200) {
					if (msg.data != null) {
						$("#id").val(msg.data.id);
						if (msg.data.collect == 0) {
							$('.contactStore').eq(0).html('收藏店铺');
						} else {
							$('.contactStore').eq(0).html('店铺已收藏');
						}
						$("#user_id").val(msg.data.user_id);
						$(".icon").attr('src', '/Images/Information/' + msg.data.image);
						$(".name").eq(0).html(msg.data.name);
						$(".name").eq(0).attr('title',msg.data.name);
						$(".name").eq(1).html(msg.data.username);
						$(".name").eq(2).html(msg.data.shop_name);
						$(".name").eq(3).html(msg.data.shop_volume);
						$(".name").eq(4).html(msg.data.trading_count + msg.data.service_count);
						$(".name").eq(5).html(msg.data.trading_count);
						$(".name").eq(6).html(msg.data.service_count);
						$(".name").eq(7).html("");
						if (msg.data.label_shop.length > 0) {
							for (var i = 0; i < msg.data.label_shop.length; i++) {
								if ($.inArray(msg.data.label_shop[i].id + '', msg.data.label) != -1) {
									$(".name").eq(7).append('<span class="labels">' + msg.data.label_shop[i].name + '</span>');
								}
							}
						}

						if (index == 1) {
							$('.sortType').eq(2).hide();
							$('.num').html(msg.data.count);
							$('.currentPage').html(page);
							var pages = Math.ceil(msg.data.count / 20);
							$('.allPage').html(pages);
							$(".count").html(msg.data.count);
							var re = /^[0-9]+$/;
							var market = "";//商品
							//商品
							if (msg.data.trading.length != 0) {
								for (var j = 0; j < msg.data.trading.length; j++) {
									var storename = cut(msg.data.trading[j].username,18);
									var money = number_format(msg.data.trading[j].store, 2, ".", ",");
									if (re.test((j + 1) / 5)) {
										market += '<div class="serviceItem mr0">';
									} else {
										market += '<div class="serviceItem">';
									}
									market += '<a class="goDetails" href="/index.php/index' +
										'/trade/trade_details.html?id=' + msg.data.trading[j].id + '">' +
										'<img src="/Images/tradingMarket/' + msg.data.trading[j].image + '"></a><div class="serviceCon">' +
										'<span class="prices">￥' + money + '</span>' +
										'<a class="serviceTitle moreline" limit="20" href="/index.php/index' +
										'/trade/trade_details.html?id=' + msg.data.trading[j].id + '">' + storename + '</a>' +
										'<a class="company text_overflow" href="store_details.html" title="">' + msg.data.trading[j].name + '</a>' +
										'<p class="volume">授权量<span class="volumeNum">' + msg.data.trading[j].value + '</span>笔</p>' +
										'</div></div>';
								}
								$(".serviceArea").eq(0).html(market);
								if (msg.data.trading.length == 0) {
									$('.page').eq(0).html('');
								} else {
									$('.page').eq(0).html(msg.data.render);
									$(".pagination").eq(0).delegate("a", "click", function () {
										var index = $("#index").val();
										var num = $(this).attr("num");
										var value = $("#value").val();
										var id = decodeURI(window.location.href.split("?")[1]);
										if (num) {
											postfile(num, id, index, value);
										}
									});
									$("#GO").on('click',function(){
										var king = $("#go").val();
										postfile(king, id, index, value);
									});
								}

							} else {
								var personnel = '<div class="nodatas">' +
									'<img src="/static/web/images/nodata.png"/>' +
									'<p>抱歉，找不到相关数据</p></div>';

								$(".serviceArea").eq(0).html(personnel);
							}

						} else {
							$('.sortType').eq(2).show();
							var res = /^[0-9]+$/;
							$('.num').html(msg.data.count);
							$('.currentPage').html(page);
							var pages = Math.ceil(msg.data.count / 20);
							$('.allPage').html(pages);
							$(".count").html(msg.data.count);
							//商品
							if (msg.data.service.length != 0 || msg.data.count != 0) {
								var service = "";//商品
								for (var e = 0; e < msg.data.service.length; e++) {
									var money = number_format(msg.data.service[e].store, 2, ".", ",");
									if (res.test((e + 1) / 5)) {
										service += '<div class="serviceItem mr0">';
									} else {
										service += '<div class="serviceItem">';
									}
									service += '<a class="goDetails" href="/index.php/index' +
										'/service/service_details.html?id=' + msg.data.service[e].id + '">' +
										'<img src="/Images/serviceGoods/' + msg.data.service[e].image + '"/></a>' +
										'<div class="serviceCon"><span class="prices">￥' + money + '</span>' +
										'<a class="serviceTitle moreline" limit="24" href="/index.php/index' +
										'/service/service_details.html?id=' + msg.data.service[e].id + '">' + msg.data.service[e].username + '</a>' +
										'<a class="company text_overflow" href="store_details.html" ' +
										'title="' + msg.data.service[e].name + '">' + msg.data.service[e].name + '</a>' +
										'<p class="volume">成交量<span class="volumeNum">' + msg.data.service[e].value + '</span>笔</p>' +
										'<p class="assess">评价<span class="assessNum">' + msg.data.service[e].rate + '</span>条</p></div></div>';
								}

								$(".serviceArea").eq(1).html(service);
								if (msg.data.service.length == 0) {
									$('.page').eq(1).html('');
								} else {
									$('.page').eq(1).html(msg.data.render);
									$(".pagination").eq(1).delegate("a", "click", function () {
										var index = $("#index").val();
										var num = $(this).attr("num");
										var value = $("#value").val();
										var id = decodeURI(window.location.href.split("?")[1]);
										if (num) {
											postfile(num, id, index, value);
										}
									});
									$("#GO").on('click',function(){
									var king = $("#go").val();
										postfile(king, id, index, value);
									});
								}
							} else {
								var personne = '<div class="nodatas">' +
									'<img src="/static/web/images/nodata.png"/>' +
									'<p>抱歉，找不到相关数据</p></div>';

								$(".serviceArea").eq(1).html(personne);
							}
						}
					} else {
						var persone = '<div class="nodatas">' +
							'<img src="/static/web/images/nodata.png"/>' +
							'<p>抱歉，找不到相关数据</p></div>';

						$(".serviceArea").html(persone);
					}
				}

				else {
					layer.msg('查询失败!', {icon: 1, time: 1000});
				}

			}
		})
    }

    // 收藏
    $('.contactStore').eq(0).on('click', function () {
        if ($('.contactStore').eq(0).text() == '店铺已收藏') {
            return false;
        }
        var id = $("#id").val();
        var userinfo = $.cookie('userinfo');
        if (userinfo) {
            var user_login = $.base64.decode(userinfo).split(",");
            $.ajax({
                type: "get",
                url: "/index.php/api/trading/info_collect",
                data: {'id': id, 'uid': user_login[0]},
                dataType: 'jsonp',
				beforeSend: function () {
                var index = layer.load(1, {
                    shade: [0.1, '#333333'] //0.1透明度的白色背景
                });
				},
                success: function (msg) {
                    layer.closeAll();
                    if (msg.code == 200) {
                        layer.msg(msg.message, {icon: 1});
                        $('.contactStore').eq(0).text("店铺已收藏")
                    }
                    if (msg.code == 1000) {
                        layer.msg(msg.message, {icon: 5});
                    }
                    if (msg.code == 1001) {
                        //layer.msg(msg.message, {icon: 6});
                        layer.msg(msg.message, {icon: 5});
                    }
                }
            });
        }else{
			layer.msg('你还没有登录！', {icon: 0});
		}
    })

    /*联系卖家*/
    $('.contactStore').eq(1).on('click', function () {
        var id = $("#contact").val();
        var userinfo = $.cookie('userinfo');
        if (userinfo) {
            var user_login = $.base64.decode(userinfo).split(",");
            var from_uid = user_login[0];
            layer.open({
                type: 2,
                title: '联系卖家',
                fix: false,
                maxmin: true,
                shadeClose: true,
                scrollbar: false,
                area: ['560px', '490px'],
                content: 'contact.html?id=' + id,
                btn: ['发送', '取消'],
                yes: function (index, layero) {
                    //do something

                    var body = layer.getChildFrame('body', index);
                    // var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    //得到iframe页的body内容
                    var content = body.find('#news_title').val();
                    var to_uid = $("#user_id").val();

                    layer.close(index);//如果设定了yes回调，需进行手工关闭
                    if (content != '' || title != '') {
                        $.ajax({
                            type: "get",
                            url: "{:url('api/trading/trading_chat')}",
                            data: {
                                'to_uid': to_uid,
                                'content': content,
                                'from_uid': from_uid
                            },
                            dataType: 'jsonp',
							beforeSend: function () {
							var index = layer.load(1, {
								shade: [0.1, '#333333'] //0.1透明度的白色背景
							});
							},
                            success: function (msg) {
                                layer.closeAll();
                                if (msg.code == 200) {
                                    layer.msg('发送成功！', {icon: 1}, function () {
                                    });
                                }
                                if (msg.code == 1000) {
                                    layer.msg('发送失败！', {icon: 5});
                                }
                            }
                        });
                    } else {
                        layer.msg('不能为空！', {icon: 5});
                    }
                }
            });
        } else {
            layer.msg('你还没有登录！', {icon: 0});
        }
    });

    /**推荐服务*/
    function get_view() {
        $.ajax({
            type: "get",
            url: "{:url('api/service/rand_goods')}",
            data: {'number': 2, 'order': 'rand()'},
            dataType: 'jsonp',
            success: function (msg) {
                var html = "";
                if (msg.code == 200) {
                    for (var i = 0; i < msg.data.length; i++) {
						var money = number_format(msg.data[i].price, 2, ".", ",");
                        html += '<div class="items"><a class="links" href="/index.php/index/service/service_details.html?id=' + msg.data[i].id + '">';
                        html += '<img src="/Images/serviceGoods/' + msg.data[i].pic + '" alt="' + msg.data[i].goods_name + '" /></a>';
                        html += '<div class="borderLine">';
                        html += '<span class="prices">￥' + money + '</span>';
                        html += '<a class="itemsTitle text_overflow" href="service_details.html?id=' + msg.data[i].id + '" title="' + msg.data[i].goods_name + '"></a>' + msg.data[i].goods_name + '</div></div>';
                    }
                    $('.recommendCon').eq(1).html(html);
                }
            }
        });
    }


    $('.icon-refresh').eq(0).on('click', function () {
        hot_view();
    });

    $('.icon-refresh').eq(1).on('click', function () {
        get_view();
    });

    /**推荐交易服务**/
    function hot_view() {
        $.ajax({
            type: "get",
            url: "{:url('api/trading/trading_rand')}",
            data: {'number': 2, 'order': 'rand()'},
            dataType: 'jsonp',
            success: function (msg) {
                var html = "";
                if (msg.code == 200) {
                    for (var i = 0; i < msg.data.length; i++) {
						var money = number_format( msg.data[i].store, 2, ".", ",");
                        html += '<div class="items">' +
                            '<a class="links" href="/index.php/index/trade/trade_details.html?id=' + msg.data[i].id + '">' +
                            '<img src="/Images/tradingMarket/' + msg.data[i].image + '"' +
                            ' alt="' + msg.data[i].username + '"/></a><div class="borderLine">' +
                            '<span class="prices">￥' + money + '起</span>' +
                            '<a class="itemsTitle text_overflow" href="trade_details.html?id=' + msg.data[i].id + '"' +
                            ' title="' + msg.data[i].username + '">' + msg.data[i].username + '</a></div></div>';
                    }
                    $('.recommendCon').eq(0).html(html);
                }
            }
        });
    }


</script>
{/block}